/*
 * Copyright (C) 2000-2008 Jens Nixdorf and various contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies of the Software, its documentation and marketing & publicity
 * materials, and acknowledgment shall be given in the documentation, materials
 * and software packages that this Software was used.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.mopore.jat.core.fadingmessage.calibration.wizard;

import static org.mopore.jat.gui.SingleRoundCornerRectangleFactory.produceSingleRoundCornerRectangel;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Transparency;
import java.awt.image.BufferedImage;

import org.mopore.jat.gui.SingleRoundCornerRectangleFactory.CornerType;

public class CalibrationIllustration {
	
	public static BufferedImage createIllustrationImage( CornerType cornerType ) {
		
		int width = 200;
		int height = 80;

		// create image an Graphics2D
		BufferedImage image = new BufferedImage( width, height, Transparency.BITMASK);
		Graphics2D g = image.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_RENDERING,
				RenderingHints.VALUE_RENDER_QUALITY);
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
				RenderingHints.VALUE_ANTIALIAS_ON);
		
		// draw inner content
		Paint paint = g.getPaint();
        g.setPaint( 
                new GradientPaint( 
                    0, 0, new Color( 20, 20, 20 ),
                    width, height-7, new Color( 120, 120, 255 )
                )
            );
		g.fillRect( 0, 0, width, height-7 );
		g.setPaint( paint );
		g.setColor( new Color(120, 120, 120) );
		g.fillRect( 0, height-7, width, 7 );
		
		int wWidth = 40;
		int wHeight = 16;
		
		final int bottomOffset = 7;

		int wX;
		int wY;
		
		CornerType roundedCornerType;
		
		switch ( cornerType ) {
			case UPPER_LEFT: {
				wX = 0;
				wY = 0;
				roundedCornerType = CornerType.LOWER_RIGHT;
				break;
			}
			case UPPER_RIGHT: {
				wX = width-wWidth;
				wY = 0;
				roundedCornerType = CornerType.LOWER_LEFT;
				break;
			}
			case LOWER_LEFT: {
				wX = 0;
				wY = height-wHeight-bottomOffset;
				roundedCornerType = CornerType.UPPER_RIGHT;
				break;
			}			
			default: { // LOWER_RIGHT
				wX = width-wWidth;
				wY = height-wHeight-bottomOffset;
				roundedCornerType = CornerType.UPPER_LEFT;
			}
		}
		
		Shape messageWindowArea = produceSingleRoundCornerRectangel( 
				wX, wY, wWidth, wHeight, 
				8, 4, roundedCornerType );
		g.setColor( new Color( 200,0,0 ) );
		g.fill( messageWindowArea );
		
		g.dispose();
		
		return image;
	}

}
